package com.meessiom.train.crm.fundsrecoverymanagement.service;


import com.meessiom.train.crm.fundsrecoverymanagement.model.Fundsrecoverymanagement;
import com.meessiom.train.crm.fundsrecoverymanagement.repository.FundsrecoverymanagementRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static java.util.Collections.list;

@Service
public class FundsrecoverymanagementService {

    @Autowired
    private FundsrecoverymanagementRepository fundsrecoverymanagementRepository;

    public List<Fundsrecoverymanagement> getAllFundsrecoverymanagement() {
        return fundsrecoverymanagementRepository.findAll();

    }

    public Fundsrecoverymanagement getFundsrecoverymanagementById(Long id) {
        return fundsrecoverymanagementRepository.findById(id).orElse(null);

    }

    public Fundsrecoverymanagement createFundsrecoverymanagement(Fundsrecoverymanagement fundsrecoverymanagement) {
        return fundsrecoverymanagementRepository.save(fundsrecoverymanagement);

    }

    public List<Fundsrecoverymanagement> createFundsrecoverymanagements(List<Fundsrecoverymanagement>  fundsrecoverymanagements) {
        return fundsrecoverymanagementRepository.saveAll(fundsrecoverymanagements);

    }

    public Fundsrecoverymanagement updateFundsrecoverymanagement(Long id, Fundsrecoverymanagement fundsrecoverymanagement) {
        Fundsrecoverymanagement existingFundsrecoverymanagement = fundsrecoverymanagementRepository.findById(id).orElse(null);
        if (existingFundsrecoverymanagement != null) {
            existingFundsrecoverymanagement.setCountryDate(fundsrecoverymanagement.getCountryDate());
            existingFundsrecoverymanagement.setPaymentAmount(fundsrecoverymanagement.getPaymentAmount());
            existingFundsrecoverymanagement.setRelatedCustomer(fundsrecoverymanagement.getRelatedCustomer());
            existingFundsrecoverymanagement.setRelatedOrder(fundsrecoverymanagement.getRelatedOrder());
            existingFundsrecoverymanagement.setPaymentFrequency(fundsrecoverymanagement.getPaymentFrequency());
            existingFundsrecoverymanagement.setPaymentPlan(fundsrecoverymanagement.getPaymentPlan());
            existingFundsrecoverymanagement.setPaymentMethod(fundsrecoverymanagement.getPaymentMethod());
            existingFundsrecoverymanagement.setPaymentType(fundsrecoverymanagement.getPaymentType());
            existingFundsrecoverymanagement.setOverdueStatus(fundsrecoverymanagement.getOverdueStatus());
            existingFundsrecoverymanagement.setOverdueDays(fundsrecoverymanagement.getOverdueDays());
            existingFundsrecoverymanagement.setCollectionPerson(fundsrecoverymanagement.getCollectionPerson());
            existingFundsrecoverymanagement.setRemarks(fundsrecoverymanagement.getRemarks());
            existingFundsrecoverymanagement.setSystemNumber(fundsrecoverymanagement.getSystemNumber());
            existingFundsrecoverymanagement.setApprover(fundsrecoverymanagement.getApprover());
            existingFundsrecoverymanagement.setSubmissionTime(fundsrecoverymanagement.getSubmissionTime());
            existingFundsrecoverymanagement.setSubmitter(fundsrecoverymanagement.getSubmitter());
            existingFundsrecoverymanagement.setNotificationRecipients(fundsrecoverymanagement.getNotificationRecipients());
            existingFundsrecoverymanagement.setApprovalTime(fundsrecoverymanagement.getApprovalTime());

        }
        fundsrecoverymanagementRepository.save(existingFundsrecoverymanagement);
        return existingFundsrecoverymanagement;
    }

    public Fundsrecoverymanagement deleteFundsrecoverymanagement(Long id) {
        Fundsrecoverymanagement existingFundsrecoverymanagement = fundsrecoverymanagementRepository.findById(id).orElse(null);
        if (existingFundsrecoverymanagement != null) {
            fundsrecoverymanagementRepository.delete(existingFundsrecoverymanagement);
        }
        return existingFundsrecoverymanagement;
    }

}
